package com.ctgu.springboot.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.common.Result;
import com.ctgu.springboot.entity.Team;
import com.ctgu.springboot.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zzs
 * @since 2023-02-13
 */
@RestController
@RequestMapping("/team")
public class TeamController {

    @Autowired
    private TeamService teamService;

    //新增团队
    @PostMapping("/save")
    public Result save(@RequestBody Team team) {
        return teamService.save(team) ? Result.suc() : Result.fail();
    }

    //更新团队信息
    @PostMapping("/update")
    public Result update(@RequestBody Team team) {
        return teamService.updateById(team) ? Result.suc() : Result.fail();
    }


    //通过ID删除团队
    @GetMapping("/del")
    public Result del(@RequestParam String team_id) {
        return teamService.removeById(team_id) ? Result.suc() : Result.fail();
    }


    //分页查询团队信息
    @PostMapping("/listPage")
    public Result listPage(@RequestBody QueryPageParam query) {
        IPage<Team> result = teamService.teamPage(query);
        return Result.suc(result.getRecords(), result.getTotal());
    }


    //获取团队信息不以分页形式展示
    @GetMapping("getList")
    public List<Team> getList(){
        return teamService.getList();
    }



}
